package com.dutychain;

import com.dutychain.handler.Handler;
import com.dutychain.handler.impl.BodyCheckHandler;
import com.dutychain.handler.impl.HeadCheckHandler;
import com.dutychain.handler.impl.TailCheckHandler;
import com.dutychain.request.HttpRequest;

public class Test {
    public static void main(String[] args) {
        HttpRequest httpRequest = buildRequest();
        Handler handler = buildHandler2();
        handler.doFilter(httpRequest);
    }

    // 责任链组合一，仅检查Head & Body
    public static Handler buildHandler () {
        Handler handler = new HeadCheckHandler();
        handler.setNext(new BodyCheckHandler());
        return handler;
    }

    // 责任链组合二，检查Head, Body and Tail
    public static Handler buildHandler2 () {
        Handler handler = new HeadCheckHandler();
        handler.setNext(new BodyCheckHandler());
        handler.getNext().setNext(new TailCheckHandler());
        return handler;
    }

    // 构造请求消息
    public static HttpRequest buildRequest() {
        HttpRequest req = new HttpRequest();

        HttpRequest.Message msg = req.new Message();
        msg.setHeader("1");
        msg.setBody("2");
        msg.setTail("");

        req.setMessage(msg);

        return req;
    }

}
